package com.sunforum.forum.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sunforum.common.annotation.Log;
import com.sunforum.common.core.controller.BaseController;
import com.sunforum.common.core.domain.AjaxResult;
import com.sunforum.common.enums.BusinessType;
import com.sunforum.forum.domain.PcRole;
import com.sunforum.forum.service.IPcRoleService;
import com.sunforum.common.utils.poi.ExcelUtil;
import com.sunforum.common.core.page.TableDataInfo;

/**
 * pc_角色管理Controller
 * 
 * @author sunforum
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/forum/role")
public class PcRoleController extends BaseController
{
    @Autowired
    private IPcRoleService pcRoleService;

    /**
     * 查询pc_角色管理列表
     */
    @PreAuthorize("@ss.hasPermi('forum:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcRole pcRole)
    {
        startPage();
        List<PcRole> list = pcRoleService.selectPcRoleList(pcRole);
        return getDataTable(list);
    }

    /**
     * 导出pc_角色管理列表
     */
    @PreAuthorize("@ss.hasPermi('forum:role:export')")
    @Log(title = "pc_角色管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PcRole pcRole)
    {
        List<PcRole> list = pcRoleService.selectPcRoleList(pcRole);
        ExcelUtil<PcRole> util = new ExcelUtil<PcRole>(PcRole.class);
        util.exportExcel(response, list, "pc_角色管理数据");
    }

    /**
     * 获取pc_角色管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('forum:role:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pcRoleService.selectPcRoleById(id));
    }

    /**
     * 新增pc_角色管理
     */
    @PreAuthorize("@ss.hasPermi('forum:role:add')")
    @Log(title = "pc_角色管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcRole pcRole)
    {
        return toAjax(pcRoleService.insertPcRole(pcRole));
    }

    /**
     * 修改pc_角色管理
     */
    @PreAuthorize("@ss.hasPermi('forum:role:edit')")
    @Log(title = "pc_角色管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcRole pcRole)
    {
        return toAjax(pcRoleService.updatePcRole(pcRole));
    }

    /**
     * 删除pc_角色管理
     */
    @PreAuthorize("@ss.hasPermi('forum:role:remove')")
    @Log(title = "pc_角色管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pcRoleService.deletePcRoleByIds(ids));
    }
}
